$(document).ready(function(){
	$("#loginbtn").click(function(){
		var nameStr = $("#nameinput")[0].value;
		var passwordStr = $("#passwordinput")[0].value;
		$.post("?a=chkuser",
		{
			name:		nameStr,
			password:	passwordStr
		},
		function(data){
			if(data == "ok")
				parent.location = "?a=index";
			else if(data == "no")
				alert("无此账号，请注册");
			else if(data == "wrong")
				alert("密码错误");
			else if(data == "noactive")
				show_pop_box("<p style=\"padding:20px\">请在邮箱中点击激活邮件的链接</p>");
			else
				alert("错误！\n"+data);
		});
	});
	
	$("#forgetbtn").click(function(){
		$('#forgetpassword').slideToggle();
	});
	
	$("#emailsubmit").click(function(){
		$("#emailsubmit")[0].disabled = true;
		$("#emailsubmit")[0].value = "正在检查email……" ;

		var emailStr = $("#emailinput")[0].value;
		if( emailStr.match(/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/) == null )
		{
			$("#emailsubmit")[0].value = "email格式错误，请检查" ;
			setTimeout( '$(\"#emailsubmit\")[0].value = \"发送激活邮件\" ;$(\"#emailsubmit\")[0].disabled = false' ,1000);
		}
		else
		{
			$.post("?a=chkemail",{ email:emailStr},
			function(data,status){
				if(data == "ok")
				{
					$("#emailsubmit")[0].value = "没有该email的注册信息，请检查" ;
					setTimeout( '$(\"#emailsubmit\")[0].value = \"发送激活邮件\" ;$(\"#emailsubmit\")[0].disabled = false' ,1000);
				}
				else if(data == "has")
				{
					$("#emailsubmit")[0].value = "正在发送忘记密码email……";
					$.post("?a=forgetpassword",{email:emailStr},
					function(){
						parent.location = "?a=showinfo&info=邮件发送完成，请检查您的邮箱。";
					});
				}
				else
				{
					$("#emailsubmit")[0].value = "未知错误，请联系管理员" ;
					setTimeout( '$(\"#emailsubmit\")[0].value = \"发送激活邮件\" ;$(\"#emailsubmit\")[0].disabled = false' ,1000);
				}
			});
		}
	});
});
